home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3388 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.1 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Processor Fault!!??
  5. Date: 28 Jan 1996 16:49:09 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Jan28094909@qcd.lanl.gov>
  8. References: <Pine.A32.3.91j.960128010358.43648E-100000@homer23.u.washington.edu>
  9. NNTP-Posting-Host: qcd.lanl.gov
  10. Mime-Version: 1.0
  11. Content-Type: text
  12. In-reply-to: "Q. Sun"'s message of Sun, 28 Jan 1996 01:13:18 -0800
  13.  
  14. In article
  15. <Pine.A32.3.91j.960128010358.43648E-100000@homer23.u.washington.edu>
  16. "Q. Sun" <quanger@u.washington.edu> writes: 
  17. <snip>
  18.    I was doing some examples off a text we are using and I am having 
  19.    problems with it. The chapter is on arrays and I type in and ran the 
  20.    programs in the text. When I ran it using Turbo C++ 3.1 it gave a nasty 
  21.    General Protection Fault and stating it's the processor's fault! It also 
  22.    said things like "0x211F:0x00BE Processor Fault." In Windows 95 it total 
  23.    crashed! But in Windows for Workgroups 3.11, it recovered a 
  24.    couple of runs until it eventually kicked me out to DOS.
  25.  
  26.    I'm running a Pentium 120 with 16megs of RAM. Do I have one of those old 
  27.    faulty Pentiums? My system is about one week new.
  28.  
  29. The most common errors are programming errors: even on faulty
  30. processors, it is rare that you discover a fault so easily. What you
  31. have to realize is that the compiler interprets what you wrote in your
  32. C source and converts what _it_ understood to `machine code'. It is
  33. very easy to write source code that the compiler cannot understand: in
  34. such cases, the compiler will tell you that. On the other hand,
  35. sometimes you can write code which violates _assumptions_ which
  36. compilers make about what you are doing, and which it doesn't
  37. specifically check for. In such cases, you will get no warning, but
  38. the compiled machine code could be completely meaningless. Called upon
  39. to do such meaningless tasks, a processor could easily `fault': That
  40. is no fault of the processor :-)
  41.  
  42.  
  43.    The code example is EXACTLY as follows:
  44. <snip>
  45.    main ()
  46.  
  47. This is completely unrelated, but defaulting the return type of a
  48. function is not good style. You should write `int main()' at least,
  49. and `int main(void)' or `int main(int argc, char*argv[])' are the
  50. preferred forms.
  51.  
  52. <snip>
  53.        int number_to_convert;
  54. <snip>
  55.        scanf  ("%ld", &number_to_convert);
  56.  
  57. This is a problem. You are telling the compiler to pass the format
  58. string %ld and the address of number_to_convert to scanf. A compiler
  59. is not required to check that the format string matches the variable
  60. that you are trying to fill: it just assumes you know what you are
  61. doing. %ld instructs scanf to fill a _long_ variable, not an _int_
  62. variable. 
  63.  
  64. Cheers
  65. Tanmoy
  66. --
  67. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  68. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  69. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  70. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  71. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  72. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  73.